package com.xian.string;

public class StringAPIOtherDemo5 {
    public static void main(String[] args) {

        // 1、public int length():获取字符串的长度
        String name = "我爱你中国love";
        System.out.println(name.length());

        // 2、public char charAt(int index):获取某个索引位置处的字符
        char c = name.charAt(1);
        System.out.println(c);

        System.out.println("--------------遍历字符串的每一个字符-----------------------");
        for (int i = 0; i < name.length(); i++) {
            char c1 = name.charAt(i);
            System.out.println(c1);
        }

        // 3、public char[] toCharArray(): :把字符串转换成字符数组
        char[] chars = name.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char aChar = chars[i];
            System.out.println(aChar);
        }

        // 4、public String substring(int beginIndex,int endIndex) :包前不包后的
        String name2 = "Java是最厉害的编程语言！！！";
        System.out.println(name2.substring(0, 9));
        // 5、public String substring(int beginIndex):从当前索引一直截取到末尾
        System.out.println(name2.substring(4));

        // 6、public string replace(CharSequence target，CharSequence replacement)
        System.out.println(name2.replace("Java", "$$$"));

        // 7、public boolean contains(charSequence s) //包含
        System.out.println(name2.contains("Java"));  //true

        // 8、public boolean startsWiths(String prefix)
        System.out.println(name2.startsWith("java"));  //false
        System.out.println(name2.startsWith("Java"));  //true

        // 9、public string[] split(string s):按照某个内容把字符串分割成字符串数组返回。
        String name4 = "王宝强，贾乃亮，郑凯";
        String[] names = name4.split("，");
        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i]);
        }

    }
}
